package com.rxy.curator;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

import java.util.Random;

public class Create_Session_Curator {
    // 创建会话
    public static void main(String[] args) {
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
        CuratorFramework client = CuratorFrameworkFactory.newClient("192.168.31.247:2181", retryPolicy);
        client.start();
        System.out.println("Zookeeper session1 established. ");
        // 使用Fluent编程风格
        CuratorFramework client1 = CuratorFrameworkFactory.builder()
                .connectString("192.168.31.247:2181") // server地址
                .sessionTimeoutMs(5000) // 会话超时时间
                .connectionTimeoutMs(3000) // 连接超时时间
                .retryPolicy(retryPolicy) // 重试策略
                .namespace("base") // 独立命名空间 /base
                .build();
        client1.start();
        System.out.println("Zookeeper session2 established. ");
    }
}
